package com.qiyang.contoller;

import com.qiyang.entity.User;
import com.qiyang.entity.UserVo;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 需加入jsckson相关依赖
 * RestController 适用前后端分离或微服务API
 * Controller 适用普通单体应用
 * @RequestBody 接收JSON数据
 * ResponseBody 响应JSON数据
 */
@RestController
// @Controller
@RequestMapping("json")
public class JsonController {

    @GetMapping("test")
    //@ResponseBody
    public User responseJson(){
        List<String> hobbies = new ArrayList<>();
        hobbies.add("乒乓球");
        hobbies.add("写代码");
        User user = new User(1001, "qinchen", null, hobbies, null, null, null);
        return user;
    }

    @PostMapping("test2")
    public User requestJson(@RequestBody UserVo userVo){
        User user = new User(userVo.getId(), userVo.getUserName(), null, null, null, null, null);
        return user;
    }

}
